package com.lookme.lmtool.cracker.filter.warping;

import com.lookme.lmtool.cracker.CrackerConstants;
import com.lookme.lmtool.cracker.annotation.FilterAnnotation;
import com.lookme.lmtool.cracker.annotation.ParamAnnotation;
import com.lookme.lmtool.cracker.filter.AbstractFilter;
import com.lookme.lmtool.utils.ImageUtils;
import com.thoughtworks.xstream.annotations.XStreamAsAttribute;

import java.awt.image.BufferedImage;
import java.awt.image.BufferedImageOp;

@FilterAnnotation(groupName = CrackerConstants.FILTER_GROUP_NAME_WARPING,name="去除白边")
public class FilterRemoveBlank extends AbstractFilter {

    @XStreamAsAttribute
    @ParamAnnotation(name = "去除左右空白", desc = "去除左右空白",inputType = ParamAnnotation.InputType.Radio,width = 100)
    boolean horizontal=true;
    @XStreamAsAttribute
    @ParamAnnotation(name = "去除上下空白", desc = "去除上下空白",inputType = ParamAnnotation.InputType.Radio,width = 100)
    boolean vertical=true;

    @Override
    public BufferedImageOp getFilter() {
        return null;
    }

    @Override
    public BufferedImage filter(BufferedImage src, BufferedImage dst) {
        BufferedImage result=src;
        try {
            if (horizontal) {
                result = ImageUtils.removeHorizontalBlank(result);
            }
            if (vertical) {
                result = ImageUtils.removeVerticalBlank(result);
            }
        }catch(Exception e){

        }
        return result;
    }
}
